import tkinter as tk

# 归并排序
def merge_sort(arr, left, right, temp):
    if left < right:
        # 整除
        mid = (left + right) // 2
        merge_sort(arr, left, mid, temp)
        merge_sort(arr, mid + 1, right, temp)

        i, j, k = left, mid + 1, 0
        while i <= mid and j <= right:
            if arr[i] < arr[j]:
                temp[k] = arr[i]
                i += 1
            else:
                temp[k] = arr[j]
                j += 1
            k += 1

        while i <= mid:
            temp[k] = arr[i]
            i += 1
            k += 1

        while j <= right:
            temp[k] = arr[j]
            j += 1
            k += 1

        for i in range(left, right + 1):
            arr[i] = temp[i - left]

def send():
    # 返回列表
    arr_str = entry.get().split()
    # 转整数
    arr = [int(x) for x in arr_str]
    temp = [0] * len(arr)
    merge_sort(arr, 0, len(arr) - 1, temp)
    result_str = ' '.join(str(x) for x in arr)
    result_label.config(text=result_str)

root = tk.Tk()
root.title("归并排序")

entry = tk.Entry(root)
entry.insert(0,'1 3 2 5 61 17 9')
entry.pack()

sort_button = tk.Button(root, text="归并排序", command=send)
sort_button.pack()

result_label = tk.Label(root, text="")
result_label.pack()

root.mainloop()